--
-- Author: shunguo.chen
-- Date: 2018-07-10 18:50:37
--
-- ItemGetActRender 解析 Res.ItemGetActNode
--

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node)
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

-- data = {item=Item/Equip/Jewel/MountSoul/Daibi, num=5}
function ClassRef:init(data)
    self.super.init(self, data)

    display.setCascadeOpacityEnabled(self, true)

    self._ui.Panel_ani:setVisible(true)
    self._timeline = self:getTimeline()
    self._timeline:gotoFrameAndPause(0)

    self._line1 = self._ui["huode_node/line1"]
    self._line2 = self._ui["huode_node/line1/line2"]

    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        local item = self._data.item
        local ui = self._ui
        local quality = item:getQuality()
        local color = Enums.QualityColor[quality]
        
        ui.Icon_kuang:loadTexture(item:getIconBg())
        ui.icon:loadTexture(item:getIcon())
        
        ui.num:setString(self._data.num)
        ui.name:setString(item:getName(true))
        ui.name:setColor(color)

        self._line1:setColor(color)
        self._line2:setColor(color)

        for i=1,5 do
            ui["cell_" .. i]:setVisible(i == quality)
        end
    end
end

function ClassRef:stopTimeline()
    self._timeline:gotoFrameAndPause(0)
end

function ClassRef:playTimeline()
    self._timeline:play("animation", false)
end

return ClassRef
